package com.banggood.upms.bean.vo;

import com.banggood.upms.bean.vo.validation.AddGroup;
import com.banggood.upms.bean.vo.validation.UpdateGroup;
import com.banggood.upms.common.constant.StatusEnum;
import lombok.*;
import org.springframework.util.CollectionUtils;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author XuChuangFeng
 */
@Data
public class SystemVo implements Serializable {

    @NotNull(message = "{validation.NotNull.id}", groups = {UpdateGroup.class})
    @Null(message = "{validation.Null.id}", groups = {AddGroup.class})
    private String systemId;

    @NotNull(message = "{validation.SystemVo.code.NotNull}", groups = {AddGroup.class})
    private String code;

    @NotNull(message = "{validation.SystemVo.name.NotNull}", groups = {AddGroup.class})
    private String name;

    private String description;

    private StatusEnum status;

    @NotNull(message = "{validation.SystemVo.metaUrl.NotNull}", groups = {AddGroup.class})
    private String metaUrl;

    private String lastSyncTime;

    private List<SystemModuleVo> modules;

    public void addModule(SystemModuleVo module) {
        if(CollectionUtils.isEmpty(this.modules)) {
            this.modules = new ArrayList<>();
        }
        this.modules.add(module);
    }
}